﻿var _global = this;

(function() {
    function Line(start, end) {
        this.Start = start;
        this.End = end;
        this.xOffset = function() { return this.Start.X == this.End.X ? 3 : 0; }
        this.yOffset = function() { return this.Start.Y == this.End.Y ? 3 : 0; }
        this.Left = function() { return this.Start.getXPixels() - this.xOffset(); }
        this.Top = function() { return this.Start.getYPixels() - this.yOffset(); }
        this.Right = function() { return (this.End.getXPixels() + this.xOffset()); }
        this.Bottom = function() { return (this.End.getYPixels() + this.yOffset()); }

    }
    _global.Line = Line;

    var isSelected = false;

    Line.prototype.draw = function(ctx) {

        var fs = ctx.fillStyle;
        if (this.isSelected) {
            ctx.fillStyle = fs;
        }
        else {
            ctx.fillStyle = "rgba(200,200,200,0.3)";
        }
        ctx.fillRect(
      this.Left(),
      this.Top(),
      this.Right() - this.Left(),
      this.Bottom() - this.Top()
      );

        ctx.fillStyle = fs;
    }

    Line.prototype.isHit = function(x, y) {
        if (y >= this.Top() && y <= this.Bottom() && x >= this.Left() && x <= this.Right()) {
            return true;
        }
        return false;
    }



    Line.prototype.select = function() {
        this.isSelected = !this.isSelected;
    }
})();